package com.ruleengine.worker.runner.rule.destination;

import com.ruleengine.destination.DestinationManager;
import com.ruleengine.destination.IDestinationProvider;
import com.ruleengine.util.model.Message;
import com.ruleengine.worker.model.Rule;
import com.ruleengine.worker.runner.rule.PubSubRuleRunner;

import io.vertx.core.Vertx;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lianghanwei on 2024/3/20
 */
@Slf4j
public class PluginRuleRunner extends PubSubRuleRunner<Message, Message> {
    private IDestinationProvider destinationProvider;
    public PluginRuleRunner(Vertx vertx,
                            String name,
                            Rule rule,
                            DestinationManager destinationManager,
                            Rule.RuleType type) {
        super(vertx, name, rule);
        this.destinationProvider = destinationManager.getDestinationProvider(type.ordinal());
    }

    @Override
    public Message process(Message item) {
        destinationProvider.send(item);
        return Message.builder().build();
    }
}
